package com.xuhai.blog19.api;

import com.xuhai.blog19.admin.entity.CommentEntity;
import com.xuhai.blog19.admin.service.CommentService;
import com.xuhai.blog19.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @Author PangJunjie
 * @Date 2023/2/10/010
 */
@RestController
@RequestMapping("/api/comment")
public class ApiCommentController {
    @Autowired
    private CommentService commentService;

    @PostMapping("/save")
    public R save(@RequestBody CommentEntity comment) {
        comment.setCommentTime(new Date());
        commentService.saveOrUpdate(comment);
        return R.ok();
    }

    @GetMapping("/{articleId}/{page}")
    public R getPageByArticleId(@PathVariable Integer articleId, @PathVariable Integer page) {
        CommentEntity comment = new CommentEntity();
        comment.setArticleId(articleId);
        comment.setStatus(1);
        comment.setCommentStatus(2);
        return R.ok().data(commentService.getPage(page, 5, comment));
    }
}
